package com.ptc.otkjavaexamples.ui;/*--------------------------------------------------------------------------*\
|
|  Module Details:
|
|  Name:    Dialog1.java
|
|  Purpose: Display the Dialog1 dialog
\*--------------------------------------------------------------------------*/

import com.ptc.cipjava.intseq;
import com.ptc.cipjava.jxthrowable;
import com.ptc.cipjava.stringseq;
import com.ptc.pfc.pfcAssembly.Assembly;
import com.ptc.pfc.pfcAssembly.ComponentPath;
import com.ptc.pfc.pfcAssembly.pfcAssembly;
import com.ptc.pfc.pfcCommand.DefaultUICommandActionListener;
import com.ptc.pfc.pfcModel.Model;
import com.ptc.pfc.pfcModelItem.ModelItemType;
import com.ptc.pfc.pfcSession.Session;
import com.ptc.uifc.uifcComponent.*;
import com.ptc.uifc.uifcDialog.*;
import com.ptc.uifc.uifcTree.*;
import com.ptc.uifc.uifcCore.*;
import com.ptc.wfc.wfcModelItem.WModelItem;
import com.ptc.wfc.wfcSession.WSession;
import com.ptc.wfc.wfcSolid.WSolid;
import sun.reflect.annotation.ExceptionProxy;


public class Dialog1 extends DefaultUICommandActionListener
{
  private String dialog1_dialog = "Dialog1";
  private String dialog1_tree1 = "Tree1";

  private Session session;
  private WSession wSession;

  public Dialog1(Session session, WSession wSession) {
    this.session = session;
    this.wSession = wSession;
  }

  @Override
  public void OnCommand() throws jxthrowable {
    Dialog1_main();
  }


  class Dialog1DialogListener extends DefaultDialogListener
  {
    Dialog1DialogListener() {}

    public void OnClose(Dialog handle)
    {
      try
      {
        uifcComponent.ExitDialog(dialog1_dialog, 0);
      }
      catch (Throwable e) {}
    }
  }


  class Tree1TreeListener extends DefaultTreeListener
  {
    Tree1TreeListener() {}

    public void OnItemSelect(Tree handle) {
    }
    public void OnItemActivate(Tree handle) {
    }
    public void OnItemOpen(Tree handle) {

    }
    public void OnItemClose(Tree handle) {}

  }

  private void testHideAndUnhide(int [] arr){
    try{
      Model model = session.GetCurrentModel();
      Assembly assembly = (Assembly) model;

      if(model==null){
        return;
      }

      WModelItem modelItem ;

      int length = arr.length;

      if(length==0){
        return;
      }else if(length==1){
        modelItem =  (WModelItem) assembly.GetItemById(ModelItemType.ITEM_FEATURE, arr[0]);
      }else {

        intseq path = intseq.create();
        for (int i = 0; i < length-1; i++) {
          path.append(arr[i]);
        }
        //        path.append(43);
        ComponentPath componentPath = pfcAssembly.CreateComponentPath(assembly, path);
        //        Selection selection = pfcSelect.CreateComponentSelection(componentPath);
        //        selection.Display();
        WSolid solid = (WSolid) componentPath.GetLeaf();
        modelItem = (WModelItem) solid.GetItemById(ModelItemType.ITEM_FEATURE, arr[length-1]);
      }



      if(modelItem.IsHidden()){
        modelItem.Unhide();
      }else {
        modelItem.Hide();
      }
    }catch (Exception e){
      System.out.println("控制显隐错误");
      e.printStackTrace();
    }

  }


  public void Dialog1_main()
  {
    try
    {
      uifcComponent.CreateDialog(dialog1_dialog, dialog1_dialog);

      Dialog dialog1 = uifcDialog.DialogFind(dialog1_dialog, dialog1_dialog);
      Dialog1DialogListener dialog1Lis = new Dialog1DialogListener();
      dialog1.AddActionListener(dialog1Lis);

      Tree tree1 = uifcTree.TreeFind(dialog1_dialog, dialog1_tree1);
      Tree1TreeListener tree1Lis = new Tree1TreeListener();
      tree1.AddActionListener(tree1Lis);

      TreeItem tech = uifcTree.TreeItemDefine("tech");
      TreeItem step = uifcTree.TreeItemDefine("step");
      step.SetText("step");
      step.SetParentName("tech");

      ItemPositionData itemPositionData = uifcCore.ItemPositionData_Create();

      tree1.InsertItem(tech,itemPositionData);

      tech.SetIsOpen(true);

      tree1.InsertItem(step,itemPositionData);



      step.SetIsOpen(true);

      String prefix = "prt";
//      for (int i =1;i<100;i++){
//        String name = prefix+i;
//        TreeItem item = uifcTree.TreeItemDefine(name);
//        item.SetParentName("tech");
//        tree1.InsertItem(item,itemPositionData);
//      }


      for (int i =101;i<103;i++){
        String name = prefix+i;
        TreeItem item = uifcTree.TreeItemDefine(name);
        item.SetParentName("step");
        tree1.InsertItem(item,itemPositionData);
      }

      String s = step.GetText();
      System.out.println(s);

      uifcComponent.ActivateDialog (dialog1_dialog);
      uifcComponent.DestroyDialog (dialog1_dialog);
    }
    catch (Throwable e) {}
  }
}
